﻿using SFML.Graphics;
using SFML.System;

namespace Midisplay
{
    internal class NoteData : Drawable
    {
        public readonly int ID;
        public readonly bool WhiteOrBlack;
        public readonly float StartTime;
        public readonly float EndTime;
        public RectangleShape Shape;

        public bool HasStarted;
        public bool HasEnded;

        public NoteData(int id, float startTime, float endTime)
        {
            ID = id;
            WhiteOrBlack = id % 12 is 0 or 2 or 4 or 5 or 7 or 9 or 11;
            StartTime = startTime;
            EndTime = endTime;
            Shape = new RectangleShape();
            float length = (EndTime - StartTime) * NoteDisplayer.NoteLengthPerSec;
            Shape.Size = new Vector2f(WhiteOrBlack ? NoteDisplayer.WhiteKeyWidth : NoteDisplayer.BlackKeyWidth, length);
            Shape.FillColor = new Color(0x77bbddff);
            Shape.OutlineThickness = 0f;

            HasStarted = false;
            HasEnded = false;
        }

        public void Draw(RenderTarget target, RenderStates states)
        {
            target.Draw(Shape, states);
        }

        public void UpdatePosition(float x, float y)
        {
            Shape.Position = new Vector2f(x, y);
        }
    }
}
